package com.hq.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hq.bean.Goods;
import com.hq.service.GoodsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Controller
public class GoodsController {
    @Resource
    private GoodsService service;
    @RequestMapping("list.do")
    public String list(@RequestParam(value = "pages",defaultValue = "1")Integer pages,String startp,String endp, Integer starts,Integer ends, Model model){
        PageHelper.startPage(pages,3);
        HashMap map = new HashMap();
        map.put("pages",pages);
        map.put("startp",startp);
        map.put("endp",endp);
        map.put("starts",starts);
        map.put("ends",ends);
        List<Goods> list = service.list(map);
        PageInfo<Goods> pageInfo = new PageInfo<>(list);
        model.addAttribute("map",map);
        model.addAttribute("pageInfo",pageInfo);
        return "list";
    }
}
